
from flask import Flask, request
from dockerImage import DockerImage

app = Flask(__name__)

dockerImage = DockerImage()

@app.route('/')
def index():
    return '<img src="http://helloflask.com/totoro.gif">'


@app.route('/docker/image/update', methods=['GET', 'POST'])
def updateImage():
    imageName = request.args.get('name')
    
    # 更新镜像
    dockerImage.update(imageName=imageName)
    return imageName


@app.route('/yunxiao/webhook/docker/image')
def dockerImageHook():
    """
    {
      "event": 'task',
      "action": 'status',
      "task": {
        "pipelineId": 183,
        "pipelineName": 'test pipeline',
        "stageName": '构建',
        "taskName": 'java构建',
        "buildNumber": 19,
        "statusCode": 'SUCCESS', \\ UNKOWN, RUNNING, WAITING, CANCELLING, CANCELED,FINISH,SUCCESS,FAIL,SKIP  
        "statusName": '运行成功',
        "pipelineUrl": 'https://rdc.aliyun.com/ec/pipelines/156539?build=19',
        "message": '[test pipeline]流水线阶段[构建]任务[java构建]运行成功'
      },
      "sources": [
        {
          "repo": 'git@gitlab:test.git',
          "branch": 'master',
          "commitId": 'xdfdfdff',
          "privousCommitId": 'ddddd',
        }
      ],
      "globalParams": {
        "key1": 'aaa',
        "key2": 'bbb',
      }
    }
    """
    return 'home'

